package com.qezhhnjy.mall.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.product.SpuInfoDesc;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.product.service.SpuInfoDescService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * spu信息介绍 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "spu信息介绍接口")
@Slf4j
@RequestMapping("/spu-info-desc")
public class SpuInfoDescController {
    @Resource
    private SpuInfoDescService spuInfoDescService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取spu信息介绍信息")
    public BaseResult<SpuInfoDesc> get(Long id) {
        SpuInfoDesc spuInfoDesc = spuInfoDescService.getById(id);
        return BaseResult.success(spuInfoDesc);
    }

    @PostMapping("/save")
    @Operation(summary = "新增spu信息介绍信息")
    public BaseResult<SpuInfoDesc> save(@RequestBody SpuInfoDesc spuInfoDesc) {
        spuInfoDescService.save(spuInfoDesc);
        return BaseResult.success(spuInfoDesc);
    }

    @PutMapping("/update")
    @Operation(summary = "更新spu信息介绍信息")
    public BaseResult<SpuInfoDesc> update(@RequestBody SpuInfoDesc spuInfoDesc) {
        spuInfoDescService.updateById(spuInfoDesc);
        return BaseResult.success(spuInfoDesc);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取spu信息介绍信息")
    public BaseResult<Page<SpuInfoDesc>> page(@RequestBody Page<SpuInfoDesc> page) {
        spuInfoDescService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除spu信息介绍信息")
    public BaseResult<Long> delete(Long id) {
        spuInfoDescService.removeById(id);
        return BaseResult.success(id);
    }
}

